package com.huidz.calendar.luckfragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.huidz.calendar.R;
import com.huidz.calendar.mainfragment.CalendarFragment;
import com.huidz.calendar.util.Apiutils;

public class ToDayFragment extends Fragment implements View.OnClickListener {
    //用于获取视图
    private View root;

    //控件
    private RatingBar constellationtimeallratingBar, workyunqiBar, loveyunqiBar, licaiyunqiBar;
    private TextView constellationtext, constellationtime, luckynumtext, luckycolortext, todaynicetext, goldmantext, constellationmsg, lovetionsmsg, worktionsmsg, goldtionsmsg;
    private ImageView changeimg;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_today, container, false);//初始加载
        if (Apiutils.isNetworkConnecteds)
            InitView(root);
        return root;
    }

    /**
     * 初始加载视图
     */
    public void InitView(View view) {
        constellationtimeallratingBar=view.findViewById(R.id.constellationtimeallratingBar);
        workyunqiBar=view.findViewById(R.id.workyunqiBar);
        loveyunqiBar=view.findViewById(R.id.loveyunqiBar);
        licaiyunqiBar=view.findViewById(R.id.licaiyunqiBar);
        constellationtext=view.findViewById(R.id.constellationtext);
        constellationtime=view.findViewById(R.id.constellationtime);
        luckynumtext=view.findViewById(R.id.luckynumtext);
        luckycolortext=view.findViewById(R.id.luckycolortext);
        todaynicetext=view.findViewById(R.id.todaynicetext);
        goldmantext=view.findViewById(R.id.goldmantext);
        constellationmsg=view.findViewById(R.id.constellationmsg);
        lovetionsmsg=view.findViewById(R.id.lovetionsmsg);
        worktionsmsg=view.findViewById(R.id.worktionsmsg);
        goldtionsmsg=view.findViewById(R.id.goldtionsmsg);
        changeimg=view.findViewById(R.id.changeimg);
        luckycolortext.setText(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(6).getDes());
        goldmantext.setText(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(7).getDes());
        luckynumtext.setText(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(5).getDes());
        float rating=(Float.parseFloat(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(0).getDes())/2)/10;
        float loverating=(Float.parseFloat(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(2).getDes())/2)/10;
        float workrating=(Float.parseFloat(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(1).getDes())/2)/10;
        float moneyrating=(Float.parseFloat(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFonums().get(3).getDes())/2)/10;
        constellationtimeallratingBar.setRating(rating);
        loveyunqiBar.setRating(loverating);
        workyunqiBar.setRating(workrating);
        licaiyunqiBar.setRating(moneyrating);
        constellationmsg.setText(CalendarFragment.xingZuoModel.getData().getContent().getToday().getFodeses().get(0).getDes());
        selectxingzuo(CalendarFragment.xingzuo);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
//            case R.id.center_title:
//
//                break;
        }
    }

    public void selectxingzuo(String name)
    {
        switch (name) {
            case "水瓶座":
                changeimg.setBackgroundResource(R.mipmap.spz);
                constellationtext.setText(R.string.shuipingzuo);
                constellationtime.setText(R.string.shuipingtime1);
                break;
            case "双鱼座":
                changeimg.setBackgroundResource(R.mipmap.syz);
                constellationtext.setText(R.string.shuangyuzuo);
                constellationtime.setText(R.string.shuangyutime1);
                break;
            case "白羊座":
                changeimg.setBackgroundResource(R.mipmap.byz);
                constellationtext.setText(R.string.baiyangzuo);
                constellationtime.setText(R.string.baiyangtime1);
                break;
            case "双子座":
                changeimg.setBackgroundResource(R.mipmap.sziz);
                constellationtext.setText(R.string.shuangzizuo);
                constellationtime.setText(R.string.shuangzitime1);
                break;
            case "金牛座":
                changeimg.setBackgroundResource(R.mipmap.jnz);
                constellationtext.setText(R.string.jinniuzuo);
                constellationtime.setText(R.string.jinniutime1);
                break;
            case "巨蟹座":
                changeimg.setBackgroundResource(R.mipmap.jxz);
                constellationtext.setText(R.string.juxiezuo);
                constellationtime.setText(R.string.juxietime1);
                break;
            case "狮子座":
                changeimg.setBackgroundResource(R.mipmap.szz);
                constellationtext.setText(R.string.shizizuo);
                constellationtime.setText(R.string.shizitime1);
                break;
            case "处女座":
                changeimg.setBackgroundResource(R.mipmap.cnz);
                constellationtext.setText(R.string.chunvzuo);
                constellationtime.setText(R.string.chunvtime1);
                break;
            case "天秤座":
                changeimg.setBackgroundResource(R.mipmap.tcz);
                constellationtext.setText(R.string.tianchengzuo);
                constellationtime.setText(R.string.tianchengtime1);
                break;
            case "天蝎座":
                changeimg.setBackgroundResource(R.mipmap.txz);
                constellationtime.setText(R.string.tianxietime1);
                constellationtext.setText(R.string.tianxiezuo);
                break;
            case "射手座":
                changeimg.setBackgroundResource(R.mipmap.ssz);
                constellationtext.setText(R.string.sheshouzuo);
                constellationtime.setText(R.string.sheshoutime1);
                break;
            case "摩羯座":
                changeimg.setBackgroundResource(R.mipmap.mjz);
                constellationtext.setText(R.string.mojiezuo);
                constellationtime.setText(R.string.mojietime1);
                break;
        }
    }
}